﻿

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using MySql.Data.MySqlClient;

public class DAL_tbl_siconide_crushing
{
    public DAL_tbl_siconide_crushing()
    {

    }



    public List<tbl_siconide_crushing> select(int ID)
    {
        List<tbl_siconide_crushing> list = new List<tbl_siconide_crushing>();
        MySqlCommand cmd = new MySqlCommand();
        cmd.CommandText = "Select ID,Charge_Number,Quantity,Flowbin_Number,Crushing_Date,Remark,IS_ACTIVE,CREATED_BY,CREATED_DATE,UPDATED_BY,UPDATED_DATE from tbl_siconide_crushing where ID=@ID";
        cmd.Parameters.AddWithValue("@ID", ID);
        DataTable dt = DBUtil.ExecuteDataTable(cmd);
        foreach (DataRow dr in dt.Rows)
        {
            list.Add(new tbl_siconide_crushing()
            {
                ID = Convert.ToInt32(dr["ID"]),
                Charge_Number = Convert.ToDecimal(dr["Charge_Number"]),
                Quantity = Convert.ToDecimal(dr["Quantity"]),
                Flowbin_Number = Convert.ToDecimal(dr["Flowbin_Number"]),
                Crushing_Date = dr["Crushing_Date"].toDateTimeWithoutError(),
                Remark = dr["Remark"].ToString(),
                IS_ACTIVE = Convert.ToBoolean(dr["IS_ACTIVE"]),
                CREATED_BY = dr["CREATED_BY"].ToString(),
                CREATED_DATE = dr["CREATED_DATE"].toDateTimeWithoutError(),
                UPDATED_BY = dr["UPDATED_BY"].ToString(),
                UPDATED_DATE = dr["UPDATED_DATE"].toDateTimeWithoutError()
            });
        }

        return list;
    }



    public List<tbl_siconide_crushing> selectAll()
    {
        List<tbl_siconide_crushing> list = new List<tbl_siconide_crushing>();
        MySqlCommand cmd = new MySqlCommand();
        cmd.CommandText = "Select ID,Charge_Number,Quantity,Flowbin_Number,Crushing_Date,Remark,IS_ACTIVE,CREATED_BY,CREATED_DATE,UPDATED_BY,UPDATED_DATE from tbl_siconide_crushing Order By ID";

        DataTable dt = DBUtil.ExecuteDataTable(cmd);
        foreach (DataRow dr in dt.Rows)
        {
            list.Add(new tbl_siconide_crushing()
            {
                ID = Convert.ToInt32(dr["ID"]),
                Charge_Number = Convert.ToDecimal(dr["Charge_Number"]),
                Quantity = Convert.ToDecimal(dr["Quantity"]),
                Flowbin_Number = Convert.ToDecimal(dr["Flowbin_Number"]),
                Crushing_Date = dr["Crushing_Date"].toDateTimeWithoutError(),
                Remark = dr["Remark"].ToString(),
                IS_ACTIVE = Convert.ToBoolean(dr["IS_ACTIVE"]),
                CREATED_BY = dr["CREATED_BY"].ToString(),
                CREATED_DATE = dr["CREATED_DATE"].toDateTimeWithoutError(),
                UPDATED_BY = dr["UPDATED_BY"].ToString(),
                UPDATED_DATE = dr["UPDATED_DATE"].toDateTimeWithoutError()
            });
        }

        return list;
    }

    public DataTable selectAllForGrid()
    {
        MySqlCommand cmd = new MySqlCommand();
        cmd.CommandText = @"Select ID,Charge_Number,Quantity,Flowbin_Number,Crushing_Date as Crushing_Date,Remark,CASE WHEN IS_ACTIVE =1 THEN 'True' ELSE 'False' END as 'IS_ACTIVE',CREATED_BY,CREATED_DATE as CREATED_DATE,UPDATED_BY,UPDATED_DATE as UPDATED_DATE from tbl_siconide_crushing Order By ID desc";

        DataTable dt = DBUtil.ExecuteDataTable(cmd);
        return dt;
    }

    public int insert(Decimal Charge_Number, Decimal Quantity, Decimal Flowbin_Number, DateTime Crushing_Date, String Remark, String CREATED_BY, DateTime CREATED_DATE)
    {
        int i = 0;
        string sql = @"Insert into tbl_siconide_crushing(Charge_Number, Quantity, Flowbin_Number, Crushing_Date, Remark, CREATED_BY, CREATED_DATE)
                        values(@Charge_Number, @Quantity, @Flowbin_Number, @Crushing_Date, @Remark, @CREATED_BY, @CREATED_DATE)";

        MySqlCommand cmd = new MySqlCommand(sql);

        cmd.Parameters.AddWithValue("@Charge_Number", Charge_Number);
        cmd.Parameters.AddWithValue("@Quantity", Quantity);
        cmd.Parameters.AddWithValue("@Flowbin_Number", Flowbin_Number);
        cmd.Parameters.AddWithValue("@Crushing_Date", Crushing_Date);
        cmd.Parameters.AddWithValue("@Remark", Remark);
        cmd.Parameters.AddWithValue("@CREATED_BY", CREATED_BY);
        cmd.Parameters.AddWithValue("@CREATED_DATE", CREATED_DATE);

        i = DBUtil.ExecuteNonQuery(cmd);
        return i;
    }



    public int update(int ID, Decimal Charge_Number, Decimal Quantity, Decimal Flowbin_Number, DateTime Crushing_Date, String Remark, String UPDATED_BY, DateTime UPDATED_DATE)
    {
        int i = 0;
        string sql = @"Update tbl_siconide_crushing SET Charge_Number=@Charge_Number, Quantity=@Quantity, Flowbin_Number=@Flowbin_Number, Crushing_Date=@Crushing_Date, Remark=@Remark, UPDATED_BY=@UPDATED_BY, UPDATED_DATE=@UPDATED_DATE WHERE ID=@ID";

        MySqlCommand cmd = new MySqlCommand(sql);

        cmd.Parameters.AddWithValue("@ID", ID);
        cmd.Parameters.AddWithValue("@Charge_Number", Charge_Number);
        cmd.Parameters.AddWithValue("@Quantity", Quantity);
        cmd.Parameters.AddWithValue("@Flowbin_Number", Flowbin_Number);
        cmd.Parameters.AddWithValue("@Crushing_Date", Crushing_Date);
        cmd.Parameters.AddWithValue("@Remark", Remark);
        cmd.Parameters.AddWithValue("@UPDATED_BY", UPDATED_BY);
        cmd.Parameters.AddWithValue("@UPDATED_DATE", UPDATED_DATE);

        i = DBUtil.ExecuteNonQuery(cmd);
        return i;
    }



    public int delete(int ID)
    {
        int i = 0;
        string sql = "Delete FROM tbl_siconide_crushing WHERE ID=@ID";

        MySqlCommand cmd = new MySqlCommand(sql);

        cmd.Parameters.AddWithValue("@ID", ID);

        i = DBUtil.ExecuteNonQuery(cmd);
        return i;
    }



}